
package com.rx.mgt.service;  

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rx.mgt.dao.EmailUserDao;
import com.rx.mgt.domain.EmailUser;
import org.springframework.transaction.annotation.Transactional;

/** 
 * ClassName:EmailUserService 
 * Function :
 * Reason   : 
 * Date     :Jan 31, 2017 9:20:58 PM 
 * @author   luolei 
 * @since    JDK 1.6
 */
@Service
public class EmailUserService {
    
    @Autowired
    EmailUserDao emailUserDao;
    @Transactional
    public EmailUser get(String id){
        return  emailUserDao.get(id);
    }
    @Transactional
    public String saveOrUpdate(EmailUser emailUser){
        if(emailUser.getUser_name()!=null){
            EmailUser user = emailUserDao.get(emailUser.getUser_name());
            if(user!=null){
                user.setPassword(emailUser.getPassword());
                user.setUser_name(emailUser.getUser_name());
                user.setPassword_hash_algorithm(emailUser.getPassword_hash_algorithm());
                user.setVersion(emailUser.getVersion());
                emailUserDao.update(user);
            }else{
                emailUserDao.save(emailUser);
            }
        }else{
            emailUserDao.save(emailUser);
        }
        return emailUser.getUser_name();
    }
    public void delete(String id){
        emailUserDao.delete(emailUserDao.get(id));
    }

    public EmailUser selectUserByUserName(String username){
       return  emailUserDao.selectUserByUserName(username);
    }
}
  